package com.jingsong.studentapp.adapter;
/*
 * @author zei , QQ:77132995, email:kazeik@163.com
 * 2021-12-18 08:01
 * 类说明:
 */

import android.content.Context;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.jingsong.studentapp.R;
import com.jingsong.studentapp.lister.OnItemEventListener;
import com.jingsong.studentapp.lister.OnSubIndexEventListener;
import com.jingsong.studentapp.model.LessonModel;
import com.jingsong.studentapp.model.WorkModel;

public class MainAdapter<A> extends BaseAdapter<A> {
    private OnSubIndexEventListener eventListener;
    private MainSubItemAdapter<LessonModel> subItemAdapter;
    private Context _context;

    public OnSubIndexEventListener getEventListener() {
        return eventListener;
    }

    public void setEventListener(OnSubIndexEventListener eventListener) {
        this.eventListener = eventListener;
    }

    public MainAdapter(Context _context) {
        this._context = _context;
    }

    @Override
    public int getLaoutView() {
        return R.layout.layout_main;
    }

    @Override
    public void onBindViewHolder(@NonNull KBaseViewHolder holder, int position) {

        TextView tvStatus = (TextView) holder.getViewById(R.id.tvStatus);
        TextView tvExamState = (TextView) holder.getViewById(R.id.tvExamState);
        TextView tvExamTitle = (TextView) holder.getViewById(R.id.tvExamTitle);
        RecyclerView rcvList = (RecyclerView) holder.getViewById(R.id.rcvItems);
        rcvList.setLayoutManager(new LinearLayoutManager(_context, RecyclerView.HORIZONTAL, false));

        TextView tvApprColor = (TextView) holder.getViewById(R.id.tvApprColor);

        subItemAdapter = new MainSubItemAdapter<>();
        rcvList.setAdapter(subItemAdapter);

        WorkModel workModel = (WorkModel) getDatas().get(position);
        subItemAdapter.setDatas(workModel.lessonModels);
        subItemAdapter.setEventListener(pos -> {
            if (null != eventListener) {
                eventListener.onItemEvent(position, pos);
            }
        });

        switch (workModel.status) {
            case 0:
                tvStatus.setText("未知");
                break;
            case 1:
                tvStatus.setText("已完成");
                tvApprColor.setBackground(holder.getContext().getResources().getDrawable(R.drawable.rount_green_shrap));
                tvStatus.setTextColor(holder.getContext().getResources().getColor(R.color.c24bb95));
                break;
            case 2:
                tvStatus.setText("未完成");
                tvApprColor.setBackground(holder.getContext().getResources().getDrawable(R.drawable.rount_red_shrap));
                tvStatus.setTextColor(holder.getContext().getResources().getColor(R.color.red));
                break;
            case 3:
                tvStatus.setText("逾期完成");
                tvApprColor.setBackground(holder.getContext().getResources().getDrawable(R.drawable.rount_green_shrap));
                tvStatus.setTextColor(holder.getContext().getResources().getColor(R.color.c24bb95));
                break;
        }

        tvExamTitle.setText(workModel.name);
        tvExamState.setText("截止时间:" + workModel.lastTime);

    }
}
